package com.sai.jsai.core.convert;

import com.sai.jsai.common.base.vo.PageResult;
import org.mapstruct.Mapper;

import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description TODO
 * @version 0.0.1
 * @author jisai
 * @createTime 2025/03/06
 */
@Mapper
public interface BaseConvert {

    default <S, T> PageResult<T> convertPageResult(PageResult<S> pageResult, Function<S, T> converter) {
        PageResult<T> result = new PageResult<>();
        result.setTotal(pageResult.getTotal());
        result.setPages(pageResult.getPages());
        result.setRecords(pageResult.getRecords().stream().map(converter).collect(Collectors.toList()));
        return result;
    }
}
